import Index from '@/pages/frontend/index.vue'
import Login from '@/pages/admin/login.vue'
import AdminIndex from '@/pages/admin/index.vue'
import Admin from '@/layouts/admin/admin.vue'
import AdminArticleList from '@/pages/admin/article-list.vue'
import AdminCategoryList from '@/pages/admin/category-list.vue'
import AdminTagList from '@/pages/admin/tag-list.vue'
import AdminBlogSetting from '@/pages/admin/blog-setting.vue'

import { createRouter, createWebHashHistory } from 'vue-router'
import ArchiveList from '@/pages/frontend/archive-list.vue'
import CategoryList from '@/pages/frontend/category-list.vue'
import TagList from '@/pages/frontend/tag-list.vue'
import CategoryArticleList from '@/pages/frontend/category-article-list.vue'
import TagArticleList from '@/pages/frontend/tag-article-list.vue'
import ArticleDetail from '@/pages/frontend/article-detail.vue'
import NotFound from '@/pages/frontend/404.vue'
import { component } from 'v-viewer'
import PublishArticleEdit from '@/pages/admin/publish-article-edit.vue'
import UpdateArticleInputEditCard from '@/components/UpdateArticleInputEditCard.vue'
import PublishArticleInputEditCard from '@/components/PublishArticleInputEditCard.vue'
import AdminWikiList from '@/pages/admin/wiki-list.vue'
import WikiList from '@/pages/frontend/wiki-list.vue'
import WikiDetail from '@/pages/frontend/wiki-detail.vue'
import RegisterIndex from '@/pages/frontend/register-index.vue'
import UserLogin from '@/pages/frontend/user-login.vue'
import PersonIndex from '@/pages/frontend/person-index.vue'
import UserPersonCenter from '@/pages/admin/user-person-center.vue'
import UserPersonCount from '@/pages/admin/user-person-count.vue'
import UserAgreement from '@/pages/frontend/user-agreement.vue'
import UserPrivacy from '@/pages/frontend/user-privacy.vue'
import AdminCommentList from '@/pages/admin/comment-list.vue'
import AdminUserList from '@/pages/admin/user-list.vue'

// 统一在这里声明所有路由
const routes = [
    {
        path: '/', // 路由地址
        component: Index, // 对应组件
        meta: { // meta 信息
            title: 'Wjblog 首页' // 页面标题
        }
    },
    {
        path: '/index', // 首页
        component: Index,
        meta: {
            title: 'Wjblog 首页'
        }
    },
    {
        path: '/login', // 登录页
        component: Login,
        meta: {
            title: '管理员登录'
        }
    },
    {
        path: '/user/login', // 登录页
        component: UserLogin,
        meta: {
            title: '用户登录'
        }
    },
    {
        path: '/user/register', // 注册页
        component: RegisterIndex,
        meta: {
            title: '账号注册中心'
        }
    },
    {
        path: '/user/person/:userId', // 个人主页
        component: PersonIndex,
        meta: {
            title: '个人主页'
        }
    },
    {
        path: '/safeguard/user/person/center', // 个人中心页
        component: UserPersonCenter,
        meta: {
            title: '个人资料中心'
        }
    },
    {
        path: '/safeguard/user/count/center', // 账号修改页
        component: UserPersonCount,
        meta: {
            title: '个人资料中心'
        }
    },
    {
        path: '/category/article/list', // 分类文章页
        component: CategoryArticleList,
        meta: {
            title: '分类列表文章详情页'
        }
    },
    {
        path: '/article/detail/:articleId', // 分类详情页
        component: ArticleDetail,
        meta: {
            title: '文章详情页'
        }
    },
    {
        path: '/wiki/detail/:wikiId', // 分类详情页
        component: WikiDetail,
        meta: {
            title: '知识库详情页'
        }
    },
    {
        path: '/tag/article/list', // 分类文章页
        component: TagArticleList,
        meta: {
            title: '标签列表文章详情页'
        }
    },
    {
        path: '/category/list', // 分类页
        component: CategoryList,
        meta: {
            title: '分类列表页'
        }
    },
    {
        path: '/tag/list', // 标签页
        component: TagList,
        meta: {
            title: '标签页'
        }
    },
    {
        path: '/archive/list', // 归档页
        component: ArchiveList,
        meta: {
            title: '归档页'
        }
    },
    {
        path: '/wiki/list', // 归档页
        component: WikiList,
        meta: {
            title: '知识库'
        }
    },
    {
        path: '/agreement', // 用户协议
        component: UserAgreement,
        meta: {
            title: '用户协议'
        }
    },
    {
        path: '/privacy', // 隐私政策
        component: UserPrivacy,
        meta: {
            title: '隐私政策'
        }
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: NotFound,
        meta: {
            title: '404 页'
        }
    },
    {
        path: "/admin/publish/article/edit",
        component: PublishArticleInputEditCard,
        meta: {
            title : "撰写文章"
        }
    },
    {
        path: "/admin/update/article/edit/:articleId",
        component: UpdateArticleInputEditCard,
        meta: {
            title : "修改文章"
        }
    },
    {
        path: '/admin', //后台首页
        component: Admin, //对应admin.vue布局文件
        //使用到admin布局的子路由
        children: [
            {
                path: "/admin/index",
                component: AdminIndex, //主要内容区
                meta: {
                    title: "WjBlog后台首页"
                }
            },
            {
                path: "/admin/article/list",
                component: AdminArticleList,
                meta: {
                    title: '文章管理'
                }
            },
            {
                path: "/admin/category/list",
                component: AdminCategoryList,
                meta: {
                    title: '分类管理'
                }
            },
            {
                path: "/admin/tag/list",
                component: AdminTagList,
                meta: {
                    title: '标签管理'
                }
            },
            {
                path: "/admin/blog/setting",
                component: AdminBlogSetting,
                meta: {
                    title: '博客设置'
                }
            },
            {
                path: "/admin/wiki/list",
                component: AdminWikiList,
                meta: {
                    title: '知识库管理'
                }
            },
            {
                path: "/admin/comment/list",
                component:  AdminCommentList,
                meta: {
                    title: '评论管理'
                }
            },
            {
                path: "/admin/user/list",
                component:  AdminUserList,
                meta: {
                    title: '用户管理'
                }
            },
        ]

    }
]

// 创建路由
const router = createRouter({
    // 指定路由的历史管理方式，hash 模式指的是 URL 的路径是通过 hash 符号（#）进行标识
    history: createWebHashHistory(),
    // routes: routes 的缩写
    routes, 
    // 每次切换路由后，页面滚动到顶部
    scrollBehavior() {
        return { top: 0 }
    }
})

// ES6 模块导出语句，它用于将 router 对象导出，以便其他文件可以导入和使用这个对象
export default router
